package org.cainiao.servlet.storage.mybatisplus.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.cainiao.servlet.storage.mybatisplus.entity.acl.User;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static org.cainiao.servlet.util.DaoUtil.DEFAULT_PAGE;
import static org.cainiao.servlet.util.DaoUtil.DEFAULT_PAGE_SIZE;

/**
 * 用户管理
 * <p>
 * Author: Cai Niao(wdhlzd@163.com)<br />
 */
@RestController
@RequestMapping("rest")
@RequiredArgsConstructor
public class TestRestController {

    @PostMapping("post")
    @Operation(summary = "测试返回对象的 POST 请求")
    public User addOrEditUser(@Parameter(description = "用户") @RequestBody User user) {
        return new User();
    }

    @GetMapping("get")
    @Operation(summary = "测试返回对象的 GET 请求")
    public User userPage(
        @Parameter(description = "当前页") @RequestParam(required = false, defaultValue = DEFAULT_PAGE) int current,
        @Parameter(description = "每页显示记录数") @RequestParam(required = false, defaultValue = DEFAULT_PAGE_SIZE) int size,
        @Parameter(description = "搜索关键词") @RequestParam(required = false) String key) {

        return new User();
    }

    @GetMapping("user/{userId}")
    @Operation(summary = "测试返回对象的带路径参数的 GET 请求")
    public User userDetail(@Parameter(description = "用户 ID", required = true) @PathVariable long userId) {
        return new User();
    }

    @GetMapping("user/{userId}/granted-roles")
    @Operation(summary = "测试返回 ResponseEntity 的带路径参数的 GET 请求")
    public ResponseEntity<User> grantedRoles(@Parameter(description = "用户 ID", required = true) @PathVariable long userId) {
        return new ResponseEntity<>(new User(), HttpStatus.OK);
    }
}
